import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_app/main/main/system/system_child.dart';
import 'package:flutter_app/main/main/system/system_nav.dart';

class SystemWidget extends StatefulWidget{
  const SystemWidget({super.key});

  @override
  SystemPage createState() => SystemPage();
}

class SystemPage extends State<SystemWidget> with SingleTickerProviderStateMixin{

  List<String> titleList = ["体系","导航"];
  int count = 0;
  late TabController tabController;
  GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();

  @override
  void initState() {
    count = titleList.length;
    tabController = TabController(length: count, vsync: this);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      key: scaffoldKey,
      appBar: PreferredSize(
          preferredSize: const Size.fromHeight(40),
          child: AppBar(
            elevation: 0,
            title: count > 0
                ? TabBar(
              controller: tabController,
              padding: const EdgeInsets.only(bottom: 8),
              unselectedLabelColor: Colors.white54,
              unselectedLabelStyle: const TextStyle(fontSize: 15),
              labelStyle: const TextStyle(fontSize: 15),
              physics: const BouncingScrollPhysics(),
              indicatorWeight: 0.1,
              isScrollable: true,
              tabs: titleList.map((e) => Tab(text: e)).toList(),
            )
                : null,
          )),
      body: count > 0
          ? TabBarView(
        //构建
        controller: tabController,
        children: titleList.map((e) {
          if(e.contains("体系")){
            return const SystemChildWidget();
          }else{
            return const SystemNavWidget();
          }
        }).toList(),
      )
          : null,
    );
  }
}